package il.ac.braude.sona.gui.forms.questions;

import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JRadioButton;

/**
 * The QRadioButton contains all methods for creating RadioButton question in formPanel
 *  
 * @author Ofek Ron
 * @author Avihay Avitan
 * @author Nitzan Inbar
 * @author Sasha Rozenthal
 */
public class QRadioButton extends FormQuestion {
	/**
	 * but - the JRadioButton of this question
	 */
	 private JRadioButton but;
	/**
	 * Constructs the QRadioButton.
	 * create new JRadioButton and add it to group of JRadioButtons
	 * @param name - the label of this question
	 * @param group - the group of JRadioButtons
	 */
	 public QRadioButton(String name, ButtonGroup group) {
		 super(BoxLayout.Y_AXIS);
		 but = new JRadioButton(name);
		 but.setName(name);
		 add(but);
		 group.add(but);
	 }

	 @Override
	 public void setDefaultAnswer(Object defaultAnswer) {
	 }
	 
	 @Override
	 public Object getAnswer() {
		 if (but.isSelected())
			 return but.getName();
		 return "";
	 }
	/**
	 * set the button to be selected or not
	 * @param status - the button selected or not attribute
	 */
	 public void set(boolean status)
	 {
		but.setSelected(status);
	 }

}
